package com.hemerasolutions.v2trainer.model.multimedia;



import com.hemerasolutions.v2trainer.model.base.BaseModel;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Transient;

import com.hemerasolutions.v2trainer.util.Utility;

@Entity
public class Photo extends BaseModel {

	private static final long serialVersionUID = 1L;

    @Column(length = 30)
	private String location;

    @Column(length = 30)
    private String name;

    @Column(length = 180)
	private String description;
 
    @Column    
    private int height;
    
    @Column
    private int width;

    @Column
	private boolean principal;
 
    @Column
	private boolean persisted = false;
     
    @Transient
    private byte[] content;
	
    @Transient
    public static final String FOLDER 		= "/multimedia/";



	public Photo() {
		super();
		this.location = Utility.randomString(10) + ".jpg";
	}


	
	
	public Photo(String name, String description, int height, int width,
			boolean principal) {
		super();
		this.name = name;
		this.description = description;
		this.height = height;
		this.width = width;
		this.principal = principal;
	}




	public String getFolder() {
		return FOLDER;
	}

	public Photo(String name, int height, int width, String location) {
		super();
		this.name = name;
		this.height = height;
		this.width = width;
		this.location = location;
	}

	public Photo(Photo photo){
		super();
		this.location = photo.location;
		this.name = photo.name;
		this.description = photo.description;
		this.height = photo.height;
		this.width = photo.width;
		this.persisted = photo.persisted;
		this.content = photo.content;
	}

	public boolean isPersisted() {
		return persisted;
	}




	public void setPersisted(boolean persisted) {
		this.persisted = persisted;
	}




	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public String getLocation() {
		return location;
	}

	public String getName() {
		return name;
	}

	public String getDescription() {
		return description;
	}

	public int getHeight() {
		return height;
	}

	public int getWidth() {
		return width;
	}

	public boolean isPrincipal() {
		return principal;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public void setPrincipal(boolean principal) {
		this.principal = principal;
	}

	public byte[] getContent() {
		return content;
	}

	public void setContent(byte[] content) {
		this.content = content;
	}




	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((description == null) ? 0 : description.hashCode());
		result = prime * result + height;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result
				+ ((location == null) ? 0 : location.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + (persisted ? 1231 : 1237);
		result = prime * result + (principal ? 1231 : 1237);
		result = prime * result + width;
		return result;
	}




	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		Photo other = (Photo) obj;
		if (description == null) {
			if (other.description != null) {
				return false;
			}
		} else if (!description.equals(other.description)) {
			return false;
		}
		if (height != other.height) {
			return false;
		}
		if (id == null) {
			if (other.id != null) {
				return false;
			}
		} else if (!id.equals(other.id)) {
			return false;
		}
		if (location == null) {
			if (other.location != null) {
				return false;
			}
		} else if (!location.equals(other.location)) {
			return false;
		}
		if (name == null) {
			if (other.name != null) {
				return false;
			}
		} else if (!name.equals(other.name)) {
			return false;
		}
		if (persisted != other.persisted) {
			return false;
		}
		if (principal != other.principal) {
			return false;
		}
		if (width != other.width) {
			return false;
		}
		return true;
	}	


	
}
